package com.ruoyi.web.controller.wuyi;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wuyi.domain.WyNongyaoInfo;
import com.ruoyi.wuyi.service.IWyNongyaoInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药信息Controller
 * 
 * @author ruoyi
 * @date 2022-07-15
 */
@RestController
@RequestMapping("/wuyi/nongyao")
public class WyNongyaoInfoController extends BaseController
{
    @Autowired
    private IWyNongyaoInfoService wyNongyaoInfoService;

    /**
     * 查询农药信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyNongyaoInfo wyNongyaoInfo)
    {
        startPage();
        List<WyNongyaoInfo> list = wyNongyaoInfoService.selectWyNongyaoInfoList(wyNongyaoInfo);
        return getDataTable(list);
    }

    /**
     * 导出农药信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:export')")
    @Log(title = "农药信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyNongyaoInfo wyNongyaoInfo)
    {
        List<WyNongyaoInfo> list = wyNongyaoInfoService.selectWyNongyaoInfoList(wyNongyaoInfo);
        ExcelUtil<WyNongyaoInfo> util = new ExcelUtil<WyNongyaoInfo>(WyNongyaoInfo.class);
        util.exportExcel(response, list, "农药信息数据");
    }

    /**
     * 获取农药信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(wyNongyaoInfoService.selectWyNongyaoInfoById(id));
    }

    /**
     * 新增农药信息
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:add')")
    @Log(title = "农药信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyNongyaoInfo wyNongyaoInfo)
    {
        return toAjax(wyNongyaoInfoService.insertWyNongyaoInfo(wyNongyaoInfo));
    }

    /**
     * 修改农药信息
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:edit')")
    @Log(title = "农药信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyNongyaoInfo wyNongyaoInfo)
    {
        return toAjax(wyNongyaoInfoService.updateWyNongyaoInfo(wyNongyaoInfo));
    }

    /**
     * 删除农药信息
     */
    @PreAuthorize("@ss.hasPermi('wuyi:nongyao:remove')")
    @Log(title = "农药信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(wyNongyaoInfoService.deleteWyNongyaoInfoByIds(ids));
    }
}
